<template>
  <div>
    <el-menu style="width: 200px;min-height: calc(100vh - 50px)" default-active="user" :default-openeds="[1]"
              router
             class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" :collapse="isCollapse">
      <el-submenu index="user">
        <template #title>系统管理</template>
        <el-menu-item index="user" :route="{path:'/'}">用户管理</el-menu-item>


      </el-submenu>
      <el-menu-item index="book" :route="{path:'/book'}">书籍管理</el-menu-item>
      <el-menu-item index="news" :route="{path:'/news'}">新闻管理</el-menu-item>
<!--      // v-if="user.role === 2"-->

    </el-menu>
  </div>
</template>

<script>
import request from "../utils/request";

export default {
  name: "Aside",
  data() {
    return {
      user:{},
      isCollapse: false//纵向展开
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log('我是打开index',key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log('我是关闭index',key, keyPath);
    },
    created(){
      //登录的时候有存储用户的缓存信息，可以获取到
      let userStr = sessionStorage.getItem("user") || "{}"
      let user = JSON.parse(userStr)
      //请求服务端，确认当前登录用户的合法信息
      request.get("/user/" + this.user.id).then(res=>{
        if (res.code='0'){
          this.user = res.data
        }
      })
    }
  }
}
</script>

<style scoped>

</style>